package com.exam.sacrifice.ui;

import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.net.Uri;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.EditText;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.exam.commonbiz.base.BaseFragment;
import com.exam.commonbiz.base.BaseViewModel;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.sacrifice.R;
import com.exam.sacrifice.databinding.FragmentZupuTabBinding;
import com.exam.sacrifice.util.WebViewJavaScriptFunction;
import com.tencent.smtt.export.external.interfaces.GeolocationPermissionsCallback;
import com.tencent.smtt.export.external.interfaces.JsPromptResult;
import com.tencent.smtt.export.external.interfaces.JsResult;
import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.ValueCallback;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class ZuPuTabFragment extends BaseFragment<BaseViewModel, FragmentZupuTabBinding> {

    private ZuPuFragment zuPuFragment;
    private BaiJiaXingFragment baiJiaXingFragment;

    public static ZuPuTabFragment newInstance() {
        ZuPuTabFragment fragment = new ZuPuTabFragment();
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_zupu_tab;
    }

    @Override
    public void initData() {

        binding.include.ivback.setVisibility(INVISIBLE);

        binding.tvZupu.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                selectFragment(0);
            }
        });

        binding.tvBaijiaxing.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                selectFragment(1);
            }
        });

        selectFragment(0);
    }

    public void selectFragment(int position) {

        binding.tvZupu.setTextColor(ContextCompat.getColor(context, R.color.black));
        binding.tvBaijiaxing.setTextColor(ContextCompat.getColor(context, R.color.black));
        if (position == 0) {
            binding.tvZupu.setTextColor(ContextCompat.getColor(context, R.color.color_f86f1b));
        } else {
            binding.tvBaijiaxing.setTextColor(ContextCompat.getColor(context, R.color.color_f86f1b));
        }
        FragmentManager fm = getActivity().getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        switch (position) {
            case 0:
                if (zuPuFragment == null) {
                    zuPuFragment = ZuPuFragment.newInstance();
                }
                ft.replace(R.id.fragment_root, zuPuFragment);
                break;
            case 1:
                if (baiJiaXingFragment == null) {
                    baiJiaXingFragment = BaiJiaXingFragment.newInstance();
                }
                ft.replace(R.id.fragment_root, baiJiaXingFragment);
                break;
            case 2:
                if (baiJiaXingFragment == null) {
                    baiJiaXingFragment = BaiJiaXingFragment.newInstance();
                }
                ft.replace(R.id.fragment_root, baiJiaXingFragment);
                break;
            default:
                break;
        }
        ft.commit();
    }

    @Override
    protected void loadData() {

    }
}
